package com.example.shopspring.controller;

import com.example.shopspring.common.ResultData;
import com.example.shopspring.entity.Student;
import com.example.shopspring.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;


@RestController
@CrossOrigin
public class HelloController {

    @Resource
    private UserService userService;

    @GetMapping("/api/get_user_by_id/{id}")
    public ResultData get_user(@PathVariable int id) {
        Optional<Student> optById = userService.getOptById(id);
        if (optById.isEmpty())
            return ResultData.error(201, "用户不存在");
        return ResultData.success(optById.get());
    }
}
